package com.example.controller;
import com.example.service.IMenuService;
import com.example.service.LoginService;
import com.example.vo.ResultVo;
import com.example.vo.reqvo.UserLoginParams;
import com.example.vo.respvo.EmpBasicInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "登录接口")
@CrossOrigin(allowCredentials = "true")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @Autowired
    private IMenuService menuService;

    @ApiOperation(value = "登录")
    @PostMapping("/login")
    public ResultVo login(@RequestBody UserLoginParams userLoginParams, HttpServletRequest request){
        return loginService.login(userLoginParams,request);
    }

    @ApiOperation(value = "退出登录")
    @GetMapping("/logout")
    public ResultVo logout(){
        return ResultVo.success("注销成功");
    }

    @ApiOperation(value = "获取用户菜单")
    @GetMapping("/user-menu")
    private ResultVo getUserMenus(HttpServletRequest request){
        return menuService.getUserMenus(request);
    }

    @ApiOperation(value = "获取登录的用户信息")
    @GetMapping("/user-info")
    public ResultVo getUserInfo(HttpServletRequest request){
        EmpBasicInfoVo loginUserInfo = loginService.getLoginUserInfo(request);
        return ResultVo.response(loginUserInfo);
    }
}
